<template>
    <view-box style="background:#F3F6F7">
        <div style="height:20px;"></div>
        <div class="width-logong">
            <div class="huiyk">
                <p style="">
                    <span>VIP服务剩余时间：</span>
                    <span style="color:#32B6C6;">{{VipTime}}</span>
                </p>
                <p style="">
                    <span style="font-size:13px;color:#bababa">VIP到期时间：</span>
                    <span style="color:#32B6C6;">{{VipTime}}</span>
                </p>
            </div>
            <div class="bottomh">
                <p class="p-width" style="color:#FE0000;">
                    <span style="color:#bababa;">VIP服务权限：系统会优先推荐您的简历或是您的公司。</span>
                </p>
            </div>
        </div>
         <div style="height:20px;"></div>
        <div class="width-logong">
            <div class="huiyk" style="display: flex;">
                <p style="width:70%;height:50px;line-height:50px;">
                    <span>月卡</span>
                    <span style="color:#32B6C6;">¥{{vipunit}}</span>
                </p>
                <p class="p-bottom" align="right"><x-button @click.native="_pay(1)" class="bottom-cpoi">购买</x-button></p>
            </div>
            <div class="bottomh">
                <p class="p-width" style="color:#FE0000;">
                    <span style="color:#bababa;">月卡服务权限：您会获得为期30天的优先推荐权限，重复购买可以累加VIP权限的时间。</span>
                </p>
            </div>
        </div>
        <div style="height:20px;"></div>
        <div class="width-logong">
            <div class="huiyk" style="display: flex;">
                <p style="width:70%;height:50px;line-height:50px;">
                    <span>季卡</span>
                    <span style="color:#32B6C6;">¥{{vipunit * 3}}</span>
                </p>
                <p class="p-bottom" align="right"><x-button @click.native="_pay(3)" class="bottom-cpoi">购买</x-button></p>
            </div>
            <div class="bottomh">
                <p class="p-width" style="color:#FE0000;">
                    <span style="color:#bababa;">季卡服务权限：您会获得为期90天的优先推荐权限，重复购买可以累加VIP权限的时间。</span>
                </p>
            </div>
        </div>
        <div style="height:20px;"></div>
        <div class="width-logong">
            <div class="huiyk" style="display: flex;">
                <p style="width:70%;height:50px;line-height:50px;">
                    <span>半年卡</span>
                    <span style="color:#32B6C6;">¥{{vipunit * 6}}</span>
                </p>
                <p class="p-bottom" align="right"><x-button @click.native="_pay(6)" class="bottom-cpoi">购买</x-button></p>
            </div>
            <div class="bottomh">
                <p class="p-width" style="color:#FE0000;">
                    <span style="color:#bababa;">半年卡服务权限：您会获得为期180天的优先推荐权限，重复购买可以累加VIP权限的时间。</span>
                </p>
            </div>
        </div>
        <div style="height:20px;"></div>
        <div class="width-logong">
            <div class="huiyk" style="display: flex;">
                <p style="width:70%;height:50px;line-height:50px;">
                    <span>年卡</span>
                    <span style="color:#32B6C6;">¥{{vipunit * 12}}</span>
                </p>
                <p class="p-bottom" align="right"><x-button @click.native="_pay(12)" class="bottom-cpoi">购买</x-button></p>
            </div>
            <div class="bottomh">
                <p class="p-width" style="color:#FE0000;">
                    <span style="color:#bababa;">年卡服务权限：您会获得为期365天的优先推荐权限，重复购买可以累加VIP权限的时间。</span>
                </p>
            </div>
        </div>
    </view-box>
</template>
<script>
import { ViewBox, Box, Flexbox, FlexboxItem, XHeader, Timeline, TimelineItem, XButton } from 'vux'
export default {
  components: {
    ViewBox,
    Box,
    Flexbox,
    FlexboxItem,
    XHeader,
    Timeline,
    TimelineItem,
    XButton
  },
  data () {
    return {
      count: 3,
      vipunit: 0,
      VipTime: ''
    }
  },
  mounted () {
    this.getVipUnit()
    this.getVipTime()
  },
  computed: {
    birth: function () {
      let mydate = new Date()
      let newdate = mydate.getFullYear()
      console.log(newdate)
      return newdate
    }
  },
  methods: {
    getVipUnit () {
      this.$http.get('/getVipUnit').then(response => {
        this.vipunit = response.data
        console.log(this.vipunit)
      }).catch(error => {
        console.log(error)
      })
    },
    getVipTime () {
      this.$http.get('/getVipTime').then(response => {
        this.VipTime = response.data
        console.log(this.VipTime)
      }).catch(error => {
        console.log(error)
      })
    },
    _pay (pic) {
      let json = {}
      let callpay = () => {
        if (typeof WeixinJSBridge === 'undefined') {
          if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
          } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
          }
        } else {
          onBridgeReady()
        }
      }
      let onBridgeReady = () => {
        WeixinJSBridge.invoke('getBrandWCPayRequest', json, (res) => {
          if (res.err_msg === 'get_brand_wcpay_request:ok') {
            this.$router.replace('/myPage')
            this.getMyYiSort()
          } else {
            this.getMyYiSort()
            this.$router.replace('/myPage')
          }
        })
      }
      this.$http.post('/openVip', {
        month: pic
      }).then((response) => {
        console.log(response.data)
        json = response.data
        callpay()
      }).catch((error) => {
        console.log(error)
      })
    }
  }
}
</script>
<style scoped lang="less">
   .width-logong{
       width: 94%;
       margin-left: 3%;
       height: auto;
       background: #fff;
       border-radius: 8px;
   }
   .huiyk{
       width: 92%;
       margin-left: 4%;
       padding-top: 5px;
       padding-bottom: 5px;
       border-bottom: 1px solid #f4f4f4;
       height:auto;
   }
   .bottomh{
       width: 100%;
       height: auto;
       display: flex;
   }
   .p-width{
       width: 92%;
       margin-left: 4%;
       padding-top: 10px;
       padding-bottom: 10px;
   }
   .p-bottom{
       width: 30%;
   }
   .bottom-cpoi{
       background: rgba(0, 0, 0, 0);
       color: #fff;
       font-weight: 500;
       border: 1px solid #32B6C6;
       background: #32B6C6;
       width: 70px;
       height: 35px;
       border-radius: 80px;
       line-height: 35px;
       margin-top: 12px;
   }
</style>
<style>
    .vux-label{
        font-size: 16px !important;
    }
    .weui-cell__ft{
        font-size: 14px;
    }
    .weui-cell_access{font-size: 14px;}
</style>